<?php
// +----------------------------------------------------------------------
// | 中联致远服务端框架
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://www.zhongliansoft.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: tony <tanyu@zhongliansoft.com>
// +----------------------------------------------------------------------

namespace app\Manage\controller;

use app\common\controller\Manage;
use app\common\model\ViewGetYears as ViewGetYearsModel;
use app\common\model\ViewGetSeasons as ViewGetSeasonsModel;
use app\common\model\ViewGetDepts as ViewGetDeptsModel;
use app\common\model\ViewGetSpecicalties as ViewGetSpecicaltiesModel;
use app\common\model\SubCenter as SubCenterModel;
use app\common\model\ViewGetClasses as ViewGetClassesModel;
use app\common\model\ViewGetDirs as ViewGetDirsModel;
use app\common\model\ViewGetTeachers as ViewGetTeachersModel;
use app\common\model\BookPrintLog as BookPrintLogModel;
use app\common\model\CwStructCache as CwStructCacheModel;
use app\common\model\StudentTypeParams as StudentTypeParamsModel;
use think\facade\Request;
use think\Db;

class BookCommon extends Manage
{/**
     * 获取年份
     * @return array
     */
    public function returnNull()
    {
        $result = [
            'status' => true,
            'data'   => [],
            'msg'    => '无数据',
            'count'  => 0
        ];

        return $result;
    }

    /**
     * 获取年份
     * @return array
     */
    public function getYears()
    {
        $viewGetYearsModel = new ViewGetYearsModel();
        $list = $viewGetYearsModel->tableData([]);
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }
    
    /**
     * 获取季度
     * @return array
     */
    public function getSeasons()
    {
        $viewGetSeasonsModel = new ViewGetSeasonsModel();
        $list = $viewGetSeasonsModel->tableData([]);
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }
    
    /**
     * 获取部门
     * @return array
     */
    public function getDepts()
    {
        $viewGetDeptsModel = new ViewGetDeptsModel();
        $list = $viewGetDeptsModel->tableData([]);
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }
    
    /**
     * 获取专业
     * @return array
     */
    public function getSpecicalties()
    {
        $viewGetSpecicaltiesModel = new ViewGetSpecicaltiesModel();
        $list = $viewGetSpecicaltiesModel->tableData(input('param.'));
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }
    
    /**
     * 获取财务班级
     * @return array
     */
    public function getCWClasses()
    {
        $post = input('param.');
        $where = [];
        if (isset($post['bmdm']) && $post['bmdm'] != "") {
            $where[] = ['bmdm', 'eq', $post['bmdm']];
        }

        if (isset($post['zydm']) && $post['zydm'] != "") {
            $where[] = ['zydm', 'eq', $post['zydm']];
        }

        $cwStructCacheModel = new CwStructCacheModel();
        $classInfo = $cwStructCacheModel->distinct(true)->field('bjdm, bjmc')
            ->where($where)
            ->order(['xsxzdm', 'rxnd'])
            ->select();
        
        $result = [
            'status' => true,
            'data'   => $classInfo,
            'msg'    => '查询成功'
        ];

        return $result;
    }

    /**
     * 获取科教中心
     * @return array
     */
    public function getSubCenter()
    {
        $post = input('param.');
        $where = [];
        if(isset($post['deptId']) && $post['deptId'] != ""){
            $where[] = ['deptId', 'eq', $post['deptId']];
        }

        $subCenterModel = new SubCenterModel();
        $list = $subCenterModel->distinct(true)
            ->where($where)
            ->select();
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }
 
    /**
     * 获取班级
     * @return array
     */
    public function getClasses()
    {
        $viewGetClassesModel = new ViewGetClassesModel();
        $list = $viewGetClassesModel->tableData(input('param.'));
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }
     
    /**
     * 获取方向
     * @return array
     */
    public function getDirs()
    {
        $viewGetDirsModel = new ViewGetDirsModel();
        $list = $viewGetDirsModel->tableData([]);
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }
    
    /**
     * 获取辅导员
     * @return array
     */
    public function getTeachers()
    {
        $viewGetTeachersModel = new ViewGetTeachersModel();
        $list = $viewGetTeachersModel->tableData([]);
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }  
    
    

    /**
     * 获取所有辅导员
     * @return array
     */
    public function getAllTeachers()
    {
        $sql = "select * from zl_view_get_teachers ";
        $list = Db::query($sql);
        
        $result = [
            'status' => true,
            'data'   => $list,
            'msg'    => '查询成功'
        ];

        return $result;
    }

    
    // 添加打印日志
    public function addPrintLog()
    {
        $this->view->engine->layout(false);
        if(Request::isPost())
        {
            $bookPrintLog = new BookPrintLogModel();
            return $bookPrintLog->addData(input('param.'));
        }
        return $this->fetch();
    }
    
    /**
     * 获取参数
     * @return array
     */
    public function getParams()
    {
        $post = input('param.');
        $where = [];
        if(isset($post['name']) && $post['name'] != ""){
            $where[] = ['p.name', 'like', '%'.$post['name'].'%'];
        } 
        if(isset($post['type_id']) && $post['type_id'] != ""){
            $where[] = ['type_id', 'eq', $post['type_id']];
        } 
        
        $studentTypeParamsModel = new StudentTypeParamsModel();
        $classInfo = $studentTypeParamsModel->distinct(true)
            ->where($where)
            ->order('sort ASC')
            ->select();
        
        $result = [
            'status' => true,
            'data'   => $classInfo,
            'msg'    => '查询成功'
        ];

        return $result;
    }
}